<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  400-611-6696  15899929162
// +----------------------------------------------------------------------
namespace app\common\dao\carwash;

use app\common\dao\BaseDao;
use app\common\model\carwash\CarwashStoreLabelModel;

class CarwashStoreLabelDao extends BaseDao
{

    /**
     * @return CarwashStoreLabelModel
     */
    protected function getModel(): string
    {
        return CarwashStoreLabelModel::class;
    }

    public function search(array $where, int $propertyId = null)
    {
        return $this->getModel()::getDB()
            ->when($propertyId !== null, function ($query) use ($propertyId) {
                $query->where('property_id', $propertyId);
            })
            ->when(isset($where['label_id']) && $where['label_id'] !== '', function ($query) use ($where) {
                $query->where('label_id', intval($where['label_id']));
            })
            ->when(isset($where['carwash_id']) && $where['carwash_id'] !== '', function ($query) use ($where) {
                $query->where('carwash_id', intval($where['carwash_id']));
            });
    }

    /**
     *  根据ID 删除标签
     * @param int $carwashId
     * @return bool
     *
     * @author Amos
     * 2024-06-06 22:40
     */
    public function deleteByCarwashId(int $carwashId)
    {
        return $this->getSearch([
            'carwash_id' => $carwashId
        ])->delete();
    }

}